<template>
	<view class="my_profile flex" @click="detail">
		<view class="photo" style="position: relative;">
			<view class="te_box" v-if="ware.tag">
				<view class="te" v-for="(item,index) in ware.tag" :key="index">{{item}}</view>
			</view>
			<image class="good_img" :src="ware.iimage" mode="widthFix"></image>
		</view>

		<block v-if="ware==undefined"></block>
		<block v-else>
			<view class="info">
				<view class="operate flex">
					<view style="width:95%;">
						<view class=" two-line name">{{ware.name}}</view>
						<view class="two-line desc">{{ware.desc}}</view>
					</view>
                   
				</view>
				<view class="flex_left_right">
					<view style="width:75%;">
						<view class="hidden">
							<text class="red_font" style="font-size: 28rpx;margin-right: 5rpx;">¥ </text>
							<text class="red_font fs-18">{{ware.money}}</text>
						</view>
					</view>

					<!-- <view class="align_center">
						<block>
							<text class="iconfont add_cart" @click="plusCart"> &#xe600;</text>
						</block>
					</view> -->
				</view>
			</view>

		</block>


	</view>
</template>

<script>
	const app = getApp().globalData;
	const {
		imgRemote
	} = app;
	let {
		log
	} = console;
	export default {
		props: ['wares', 'config', 'url'],
		watch: {
			wares(newvalue) {
				this.ware = newvalue;
			}
		},
		data() {
			return {
				apliyShow: false,
				ware: this.wares,
				imgRemote: imgRemote,
				token: uni.getStorageSync('cdj_token'),
				count: 0,
				addcount: 0,
				message: ''
			}
		},
		methods: {
			showCart() {
				this.$emit('showCart')
			},
			addcart(url, num, message = '成功加入购物车') {
				getApp().globalData.aplipay = false;
				let item = this.ware;
				if (item.is_float == 1 && !Number.isInteger(Number(num))) {
					rs.Toast('购买数量不能为小数');
					return;
				}
				let timeStamp = Math.round(new Date().getTime() / 1000);
				let obj = {
					appid: appid,
					timeStamp: timeStamp,
					item_id: item.id,
					attr_id: 0,
					item_num: num
				};
				let sign = md5.hexMD5(rs.objKeySort(obj) + appsecret);
				let params = Object.assign({
						sign: sign
					},
					obj
				);
				rs.postRequests(url, params, res => {
					let data = res.data;
					if (data.code == 200) {
						// #ifndef MP-ALIPAY
						rs.Toast(message);
						// #endif


						if (num <= 0) {
							this.ware.cart_num = 0;
						} else {

							this.ware.cart_num = num;

						}
					} else if (data.code == 407 || data.code == 406) {
						rs.Toast("购买数量不能超过活动数量");
					} else {
						rs.Toast(res.data.msg);
					}
				});
			},
			minus(e) {
				if (e == 0) {
					this.addcart('deleteCart', e, '成功删除商品');
				} else {
					this.addcart('changeNum', e);
				}
			},
			plus(e) {
				this.addcart('changeNum', e);
			},
			plusCart() {

				this.addcart('changeNum', 1);
			},
			showKey() {
				this.$emit('showKey')
			},
			detail() {


				 uni.navigateTo({
					url: '/pages/fw/info?id='+this.ware.id
				}) 



			},
			cancelCollect() {
				this.$emit('cancelCollect')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my_profile {
		/* padding: 0 0 30rpx 0; */
		background: white;
		border-bottom: 1px solid #eee;

		.tag text {
			background: $m-c;
			color: white;
			font-size: 24rpx;
			border-radius: 10rpx;
			margin-right: 10rpx;
			padding: 0 10rpx;
		}
	}

	.my_profile .photo {

		/* width: 180rpx; */

	}

	.my_profile .good_img {
		margin: 29rpx;
		border-radius: 10rpx;
		width: 180rpx;
		height: 180rpx;
	}

	.my_profile .info {
		flex: 1;
		display: flex;
		padding: 29rpx 0;
		flex-direction: column;
		justify-content: space-between;
		width: 0;
	}

	.my_profile .operate {
		height: 100%;
		justify-content: space-between;
	}

	.my_profile .add_cart {
		width: 44.4rpx;
		height: 44.4rpx;
		background: #1677fe;
		text-align: center;
		line-height: 44.4rpx;
		border-radius: 50%;
		color: white;
		margin: 0rpx 30rpx 0 0;
	}

	.my_profile .showToast {
		position: fixed;
		margin: auto;
		left: 0;
		right: 0;
		top: 12px;
		bottom: 0;
		width: 200rpx;
		height: 30rpx;
		background: rgba(0, 0, 0, 0.7);
		border-radius: 10rpx;
		padding: 15rpx;
		color: white;
	}

	.jz_box {
		font-size: 26rpx;
		color: #FF7133;
		margin-top: 8rpx;
	}

	.jz_price_box {
		font-size: 26rpx;
		margin-top: 8rpx;
		color: #666664;
	}

	.te_box {


		position: absolute;
		right: 0rpx;
		top: 30rpx;
		display: flex;
		align-items: center;
	}

	.te {
		box-sizing: border-box;
		padding: 0 10rpx;
		height: 45rpx;
		line-height: 45rpx;
		text-align: center;
		border-radius: 10rpx;
		color: white;
		font-weight: bold;
		background-color: #1677fe;
		font-size: 20rpx;
		margin-right: 15rpx;
	}
	.name{
		font-size: 29rpx;
		color: black;
		font-weight: bold;
	}
	.desc{
		color: #83838B;
		font-size: 24rpx;
		margin-top: 10rpx;
	}
</style>